import { getRangeDateTimeByTime } from './util';

export interface DatePickerOpts {
  disabledDate: (time: Date) => boolean;
  shortcuts: {
    text: string;
    value: () => Date[];
  }[];
}

/**
 * el-datepicker 默认数据
 *
 * @param opts 默认数据
 * @returns
 */
export const InitDatePickerOpts = (opts?: DatePickerOpts) => ({
  disabledDate:
    opts?.disabledDate ??
    ((time: Date) => {
      return time.getTime() > Date.now();
    }),

  shortcuts: opts?.shortcuts ?? [
    {
      text: '今天',
      value: () => {
        const rangeData = getRangeDateTimeByTime(Date.now());
        return [new Date(+rangeData.startTime), new Date(+rangeData.endTime)];
      }
    },
    {
      text: '三天内',
      value: () => {
        const rangeData = getRangeDateTimeByTime(Date.now());
        const startTime = +rangeData.startTime - 2 * 86400000;
        return [new Date(startTime), new Date(+rangeData.endTime)];
      }
    },
    {
      text: '一周内',
      value: () => {
        const rangeData = getRangeDateTimeByTime(Date.now());
        const startTime = +rangeData.startTime - 6 * 86400000;
        return [new Date(startTime), new Date(+rangeData.endTime)];
      }
    },
    {
      text: '三十天内',
      value: () => {
        const rangeData = getRangeDateTimeByTime(Date.now());
        const startTime = +rangeData.startTime - 30 * 86400000;
        return [new Date(startTime), new Date(+rangeData.endTime)];
      }
    }
  ]
});
